﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;

namespace Benlai.Util
{
    public class ErrorLog
    {
        private static ErrorLog _incident = null;

        private static object _lockobject = new object();

        public static ErrorLog GetInstance()
        {
            if (_incident != null)
                return _incident;
            lock (_lockobject)
            {
                if (_incident != null)
                    return _incident;

                _incident = new ErrorLog();
                return _incident;
            }
        }


        private readonly log4net.ILog _loginfo = log4net.LogManager.GetLogger("ALL");

        /// <summary>
        /// 输出日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="ex"></param>
        public void Write(string errormsg, Exception ex)
        {
            _loginfo.Error(errormsg, ex);
        }



        /// <summary>
        /// 输出日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="msg"></param>
        public void Write(string msg)
        {
            if (_loginfo.IsInfoEnabled)
            {
                _loginfo.Info(msg);
            }
        }



    }
}
